home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _CF945EC52AEC478DAAC5D6B8D1E57DFE < prev    next >
Encoding:
Text File  |  2002-06-05  |  6.2 KB  |  273 lines

  1. // Copyright (C) 2001-2002 Raven Software
  2. //
  3. // bg_gametype.c -- dynamic gametype handling
  4.  
  5. #include "q_shared.h"
  6. #include "bg_public.h"
  7. #include "bg_local.h"
  8.  
  9. gametypeData_t    bg_gametypeData[MAX_GAMETYPES];
  10. int                bg_gametypeCount;
  11.  
  12. /*
  13. ===============
  14. BG_ParseGametypePhotos
  15.  
  16. Parses the photo information for objectives dialog
  17. ===============
  18. */
  19. static qboolean BG_ParseGametypePhotos ( int gametypeIndex, TGPGroup group )
  20. {
  21.     TGPGroup photo;
  22.     int         index;
  23.     char     temp[MAX_TOKENLENGTH];
  24.  
  25.     // Convienience check
  26.     if ( !group )
  27.     {
  28.         return qtrue;
  29.     }
  30.  
  31.     index = 0;
  32.     photo = trap_GPG_GetSubGroups ( group );
  33.  
  34.     while ( photo )
  35.     {
  36.         trap_GPG_GetName ( photo, temp );
  37.         bg_gametypeData[gametypeIndex].photos[index].name = trap_VM_LocalStringAlloc ( temp );
  38.  
  39.         trap_GPG_FindPairValue ( photo, "displayname", "unknown", temp );
  40.         bg_gametypeData[gametypeIndex].photos[index].displayName = trap_VM_LocalStringAlloc ( temp );
  41.  
  42.         index++;
  43.  
  44.         photo = trap_GPG_GetNext ( photo );
  45.     }
  46.  
  47.     return qtrue;
  48. }
  49.  
  50. /*
  51. ===============
  52. BG_ParseGametypeInfo
  53.  
  54. Parses minimal information about the given gametype.  For the most part
  55. this information is the name of the gametype and some of its parameters.
  56. ===============
  57. */
  58. static qboolean BG_ParseGametypeInfo ( int gametypeIndex )
  59. {
  60.     gametypeData_t*        gametype;
  61.     TGenericParser2        GP2;
  62.     TGPGroup            topGroup;
  63.     TGPGroup            gtGroup;
  64.     char                temp[1024];
  65.  
  66.     // Get the pointer for the gametype data
  67.     gametype = &bg_gametypeData[gametypeIndex];
  68.     
  69.     // Open the gametype's script file
  70.     GP2 = trap_GP_ParseFile( (char*)gametype->script, qtrue, qfalse);
  71.     if (!GP2)
  72.     {
  73.         return qfalse;
  74.     }
  75.  
  76.     // Top group should only contain the "gametype" sub group
  77.     topGroup = trap_GP_GetBaseParseGroup(GP2);
  78.     if ( !topGroup )
  79.     {
  80.         return qfalse;
  81.     }
  82.  
  83.     // Grab the gametype sub group
  84.     gtGroup = trap_GPG_FindSubGroup ( topGroup, "gametype" );
  85.     if ( !gtGroup )
  86.     {
  87.         return qfalse;
  88.     }
  89.  
  90.     // Parse out the name of the gametype
  91.     trap_GPG_FindPairValue ( gtGroup, "displayname", "", temp );
  92.     if ( !temp[0] )
  93.     {
  94.         return qfalse;
  95.     }
  96.     gametype->displayName = trap_VM_LocalStringAlloc ( temp );
  97.  
  98.     // Description
  99.     trap_GPG_FindPairValue ( gtGroup, "description", "", temp );
  100.     if ( temp[0] )
  101.     {
  102.         gametype->description = trap_VM_LocalStringAlloc ( temp );
  103.     }
  104.  
  105.     // Are pickups enabled?
  106.     trap_GPG_FindPairValue ( gtGroup, "pickups", "yes", temp );
  107.     if ( !Q_stricmp ( temp, "no" ) )
  108.     {
  109.         gametype->pickupsDisabled = qtrue;
  110.     }
  111.  
  112.     // Are teams enabled?
  113.     trap_GPG_FindPairValue ( gtGroup, "teams", "yes", temp );
  114.     if ( !Q_stricmp ( temp, "yes" ) )
  115.     {
  116.         gametype->teams = qtrue;
  117.     }
  118.  
  119.     // Display kills
  120.     trap_GPG_FindPairValue ( gtGroup, "showkills", "no", temp );
  121.     if ( !Q_stricmp ( temp, "yes" ) )
  122.     {
  123.         gametype->showKills = qtrue;
  124.     }
  125.  
  126.     // Look for the respawn type
  127.     trap_GPG_FindPairValue ( gtGroup, "respawn", "normal", temp );
  128.     if ( !Q_stricmp ( temp, "none" ) )
  129.     {
  130.         gametype->respawnType = RT_NONE;
  131.     }
  132.     else if ( !Q_stricmp ( temp, "interval" ) )
  133.     {
  134.         gametype->respawnType = RT_INTERVAL;
  135.     }
  136.     else
  137.     {
  138.         gametype->respawnType = RT_NORMAL;
  139.     }
  140.  
  141.     // A gametype can be based off another gametype which means it uses all the gametypes entities
  142.     trap_GPG_FindPairValue ( gtGroup, "basegametype", "", temp );
  143.     if ( temp[0] )
  144.     {
  145.         gametype->basegametype = trap_VM_LocalStringAlloc ( temp );
  146.     }
  147.  
  148.     // What percentage doest he backpack replenish?
  149.     trap_GPG_FindPairValue ( gtGroup, "backpack", "0", temp );
  150.     gametype->backpack = atoi(temp);
  151.  
  152.     // Get the photo information for objectives dialog
  153.     BG_ParseGametypePhotos ( gametypeIndex, trap_GPG_FindSubGroup ( gtGroup, "photos" ) );
  154.  
  155.     // Cleanup the generic parser
  156.     trap_GP_Delete ( &GP2 );
  157.  
  158.     return qtrue;
  159.  
  160. }
  161.  
  162. /*
  163. ===============
  164. BG_BuildGametypeList
  165.  
  166. Builds a list of the gametypes that are available and parses minimal
  167. information about those gametypes.
  168. ===============
  169. */
  170. qboolean BG_BuildGametypeList ( void )
  171. {
  172.     char        filename[MAX_QPATH];
  173.     char        filelist[4096];
  174.     char*        fileptr;
  175.     char*        s;
  176.     int            filelen;
  177.     int            filecount;
  178.     int            i;
  179.  
  180.     bg_gametypeCount = 0;
  181.  
  182.     // Retrieve the list of gametype files.  The returned list is a 
  183.     // null separated list with the number of entries returned by the call
  184.     filecount = trap_FS_GetFileList("scripts", ".gametype", filelist, 4096 );
  185.     fileptr   = filelist;
  186.     
  187.     for ( i = 0; i < filecount; i++, fileptr += filelen+1) 
  188.     {
  189.         // Grab the length so we can skip this file later
  190.         filelen = strlen(fileptr);
  191.  
  192.         // Build the full filename
  193.         strcpy(filename, "scripts/");
  194.         strcat(filename, fileptr );
  195.  
  196.         // Fill in what we know so far
  197.         bg_gametypeData[bg_gametypeCount].script = trap_VM_LocalStringAlloc ( filename );
  198.  
  199.         // Kill the dot so we can use the filename as the short name
  200.         s  = strchr ( fileptr, '.' );
  201.         *s = '\0';
  202.         bg_gametypeData[bg_gametypeCount].name   = trap_VM_LocalStringAlloc ( fileptr );
  203.         
  204.         // TODO: Parse the gametype file
  205.         BG_ParseGametypeInfo ( bg_gametypeCount++ );
  206.     }
  207.  
  208.     return qtrue;
  209. }
  210.  
  211. /*
  212. ===============
  213. BG_FindGametype
  214.  
  215. Returns the gametype index using the given name. If the gametype isnt found
  216. then -1 will be returned (and this is bad)
  217. ===============
  218. */
  219. int BG_FindGametype ( const char* name )
  220. {
  221.     int i;
  222.  
  223.     // Loop through the known gametypes and compare their names to 
  224.     // the name given
  225.     for ( i = 0; i < bg_gametypeCount; i ++ )
  226.     {
  227.         // Do the names match?
  228.         if ( !Q_stricmp ( bg_gametypeData[i].name, name )  )
  229.         {
  230.             return i;
  231.         }
  232.     }
  233.  
  234.     return -1;
  235. }
  236.  
  237. /*
  238. ==============
  239. BG_FindGametypeItem
  240.  
  241. Search through the item list for the gametype item with
  242. the given index.
  243. ==============
  244. */
  245. gitem_t    *BG_FindGametypeItem ( int index ) 
  246. {
  247.     return &bg_itemlist[index + MODELINDEX_GAMETYPE_ITEM];
  248. }
  249.  
  250. /*
  251. ==============
  252. BG_FindGametypeItemByID
  253.  
  254. Gametype will assign ids to the gametype items for them for future reference, the 
  255. id is crammed into the quantity field of the gametype item.  This function will
  256. find the gametype item with the given item id.
  257. ==============
  258. */
  259. gitem_t *BG_FindGametypeItemByID ( int itemid )
  260. {
  261.     int i;
  262.     
  263.     for ( i = 0; i < MAX_GAMETYPE_ITEMS; i ++ )
  264.     {
  265.         if ( bg_itemlist[i + MODELINDEX_GAMETYPE_ITEM].quantity == itemid )
  266.         {
  267.             return &bg_itemlist[i + MODELINDEX_GAMETYPE_ITEM];
  268.         }
  269.     }
  270.  
  271.     return NULL;
  272. }
  273.